package Servlet;

import Bean.Page;
import Service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;
import java.io.IOException;
import java.util.Collections;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张
 * Date: 2025-03-03
 * Time: 10:16
 */
//用户列表
@WebServlet("/UserList")
public class UserListServlet extends HttpServlet {
    private UserService userService = new UserService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf8");
        //捕获当前页数
        String pagination = req.getParameter("pageNo");
        int i = Integer.parseInt(pagination);
        //约定每页查收5条数据
        int size = 3;
        Page page = userService.select(i,size);
        System.out.println("[UserListServlet] 查询到的数据为 : " + page.getList());

        //打包数据
        req.setAttribute("list",page.getList());
        req.setAttribute("box",page);
        //跳转
        req.getRequestDispatcher("user_list.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
